import Vue from 'vue'
import VueRouter from 'vue-router'
import ClientView from '../views/ClientView.vue'
import ArticleList from '../components/article/ArticleList'
import ArticleDetail from '@/components/article/ArticleDetail'
import ArticleArchive from '@/components/article/ArchiveView'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'client',
    component: ClientView,
    children: [
      {
        path: 'article',
        component: ArticleList,
        meta: {
          title: '文章'
        }
      },
      {
        path: 'articledetail/:id',
        name: 'articledetail',
        component: ArticleDetail,
        props: true,
        meta: {
          title: '文章详情'
        }
      },
      {
        path: 'archive',
        name: 'articlearchive',
        component: ArticleArchive,
        props: true,
        meta: {
          title: '文章归档'
        }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
